/*
 *  POJ1260: Pearls
 */

/*-------- Includes --------*/
#include <iostream>
#include <algorithm>

using namespace std;

/*-------- Defines --------*/


/*-------- Types --------*/


/*-------- Global Variables --------*/
int N;          // number of category
int a[101];    // number of pearls needed in i-th class
int p[101];    // price per pearl in i-th class
int s[101];    // sum of ai from 0 to i

int d[101];    // lowest possible price

/*-------- Function Prototypes --------*/


/*-------- Main Function --------*/
int main(int argc, char const *argv[])
{
    int nCase;

    cin >> nCase;

    s[0] = 0;
    d[0] = 0;

    while (nCase--) {
        cin >> N;

        for (int i = 1; i <= N; i++) {
            cin >> a[i] >> p[i];

            s[i] = s[i-1] + a[i];

            d[i] = d[i-1] + (a[i] + 10) * p[i];

            for (int j = i - 1; j > 0; j--)
                d[i] = min(d[i], d[j-1] + (s[i] - s[j-1] + 10) * p[i]);
        }

        cout << d[N] << endl;
    }

    return 0;
}

/*-------- Functions --------*/

